package com.mxdx.edu.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.mxdx.edu.common.*;
import com.mxdx.edu.constant.StaticConstants;
import com.mxdx.edu.enums.*;
import com.mxdx.edu.model.*;
import com.mxdx.edu.service.impl.MxCertificateInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.StringUtil;
import com.mxdx.edu.common.log.AppLogger;
import com.mxdx.edu.service.ICmsCategoryService;
import com.mxdx.edu.service.IRecruitmentDictService;
import com.mxdx.edu.service.IRecruitmentPositionService;
import com.mxdx.edu.service.IResumeDeliveryRecordService;
import com.mxdx.edu.service.IResumeService;
import com.mxdx.edu.service.ISalesManInfoService;
import com.mxdx.edu.service.IStudentService;
import com.mxdx.edu.service.ISysDictService;
import com.mxdx.edu.service.IUserJobSeekerService;
import com.mxdx.edu.util.DictUtils;
import com.mxdx.edu.util.ServletUtil;
import com.mxdx.edu.util.StringUtils;

/**
 * 人事工作controller(招聘、求职)
 *
 * @author howie
 */
@Controller
@RequestMapping(value = "/personnelWork")
public class PersonnelWorkController extends BaseController {

	private AppLogger logger = new AppLogger(PersonnelWorkController.class);

	@Resource
	private ICmsCategoryService cmsCategoryService;
	@Resource
	private MxCertificateInfoService mxCertificateInfoService;
	@Resource
	private IRecruitmentPositionService recruitmentPositionService;

	@Resource
	private IStudentService studentService;

	@Resource
	private IUserJobSeekerService userJobSeekerService;

	@Resource
	private IResumeService resumeService;

	@Resource
	private ISysDictService sysDictServicel;

	@Resource
	private IRecruitmentDictService recruitmentDictService;

	@Resource
	private IResumeDeliveryRecordService resumeDeliveryRecordService;

	@Resource
	private ISalesManInfoService salesManInfoService;

	/**
	 * 求职招聘首页
	 *
	 * @return
	 */
	@RequestMapping(value = "/public/personnelIndex")
	public ModelAndView personnelIndex(HttpServletRequest request) {
		logger.entry("personnelIndex", "personnelIndex");
		ModelAndView result = new ModelAndView("h5/personnelIndex");
		String keyword = ServletUtil.getParameterStr(request, "keyword", "");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		List<Map<String, Object>> mxzxList = null;
		List<Map<String, Object>> recruitmentList = null;
		Map<String, Object> param = new HashMap<>();
		int num = 0;
		try {
			param.put("begin", num);
			param.put("endNum", 4);
			// 梦想在线
			param.put("name", CmsIdEnums.QIUZHI_PHOTO.getCode());
			param.put("displayType", DisplayTypeEnums.IMAGE.getCode());
			param.put("parentId", "b7b980576f984ecfbf41b8995cf35758");
			mxzxList = cmsCategoryService.findListByMap(param);
			logger.doInfo("mxzxList:", mxzxList);
			// 招聘信息
			param.put("keyword", String.format("%s%s%s", "%", keyword, "%"));
			recruitmentList = recruitmentPositionService.findListByMap(param);
			dealPostWithDictValue(recruitmentList);
			logger.doInfo("recruitmentList:", recruitmentList);
			logger.info("personnelIndex");
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("imageHost", imageHost);
		result.addObject("mxzxList", mxzxList);
		result.addObject("recruitmentList", recruitmentList);
		result.addObject("keyword", keyword);
		return result;
	}

	@RequestMapping(value = "/auth/checkRefereesCode")
	@ResponseBody
	public ApiResult<Map<String, Object>> checkRefereesCode(HttpServletRequest request) {
		logger.entry("checkRefereesCode", "checkRefereesCode");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String refereesCode = ServletUtil.getParameterStr(request, "refereesCode", "");
		Map<String, Object> param = new HashMap<>();
		try {
			param.put("refereesCode", refereesCode);
			boolean b = salesManInfoService.checkSalesManByMap(param);
			if (!b) {
				apiResult.setStatus("99999999");
			}
			logger.info("checkRefereesCode end");
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		return apiResult;
	}

	private void dealPostWithDictValue(List<Map<String, Object>> dataList) {
		for (Map<String, Object> data : dataList) {
			dealPostMap(data);
		}
	}

	private void dealPostMap(Map<String, Object> data) {
		String post = CommonUtils.getStrValueFromMap(data, "post", "");
		String workPlace = CommonUtils.getStrValueFromMap(data, "workPlace", "");
		String educationalRequirements = CommonUtils.getStrValueFromMap(data, "educationalRequirements", "");
		String recruitmentNature = CommonUtils.getStrValueFromMap(data, "recruitmentNature", "");
		String workingLife = CommonUtils.getStrValueFromMap(data, "workingLife", "");
		String jobPay = CommonUtils.getStrValueFromMap(data, "jobPay", "");
		String[] postIds = post.split(",");
		StringBuffer allPostName = new StringBuffer();
		int i = 1;
		for (String postId : postIds) {
			Map<String, Object> placeMap = cacheService.getPlace(postId);
			if (placeMap != null && placeMap.containsKey("name")) {
				allPostName.append(placeMap.get("name"));
				if (i != postIds.length) {
					allPostName.append(",");
				}
			}
			i++;
		}
		String companyNature = CommonUtils.getStrValueFromMap(data, "companyNature", "");
		String companyIndustry = CommonUtils.getStrValueFromMap(data, "companyIndustry", "");
		data.put("companyNatureName", DictUtils.getDictLabel(companyNature, "company_nature", ""));
		if(StringUtils.isNotBlank(companyIndustry)){
			data.put("companyIndustryName", getAllPlaceName(companyIndustry));
		}
		data.put("allPostName", allPostName);

		data.put("educationalRequirementsName",
				DictUtils.getDictLabel(educationalRequirements, "educational_requirements", ""));
		data.put("recruitmentNatureName", DictUtils.getDictLabel(recruitmentNature, "recruitment_nature", ""));
		data.put("workingLifeName", DictUtils.getDictLabel(workingLife, "working_life", ""));
		data.put("jobPayName", DictUtils.getDictLabel(jobPay, "job_pay", ""));
		if (data.get("createDate") != null) {
			Date createDate = (Date) data.get("createDate");
			data.put("createDateValue", DateFormatUtils.DateToString(createDate, DateStyle.YYYY_MM_DD));
		}

		if (data.get("refreshDate") != null) {
			Date refreshDate = (Date) data.get("refreshDate");
			data.put("refreshDate", DateFormatUtils.DateToString(refreshDate, DateStyle.YYYY_MM_DD));
		}

		String[] placeIds = workPlace.split(",");
		StringBuffer workPlaceName = new StringBuffer();
		StringBuffer allWorkPlaceName = new StringBuffer();
		i = 1;
		for (String placeId : placeIds) {
			Map<String, Object> placeMap = cacheService.getPlace(placeId);
			if (placeMap != null && placeMap.containsKey("name")) {
				allWorkPlaceName.append(placeMap.get("name"));
				if( i == (placeIds.length -1)){
					workPlaceName.append(placeMap.get("name")).append(",");
				}else if (i == placeIds.length ) {
					workPlaceName.append(placeMap.get("name"));
				} else {
					allWorkPlaceName.append(",");
				}
			}
			i++;
		}

		data.put("workPlaceName", workPlaceName);
		data.put("allWorkPlaceName", allWorkPlaceName);
	}


	public String getAllPlaceName(String workPlace){
		if(StringUtils.isEmpty(workPlace)){
			return "";
		}
		String[] placeIds = workPlace.split(",");
		StringBuffer workPlaceName = new StringBuffer();
		StringBuffer allWorkPlaceName = new StringBuffer();
		int i = 1;
		for (String placeId : placeIds) {
			Map<String, Object> placeMap = cacheService.getPlace(placeId);
			if (placeMap != null && placeMap.containsKey("name")) {
				allWorkPlaceName.append(placeMap.get("name"));
				if (i == placeIds.length) {
					workPlaceName.append(placeMap.get("name"));
				} else {
					allWorkPlaceName.append(",");
				}
			}
			i++;
		}

		return  allWorkPlaceName.toString();
	}

	/**
	 * 我要找工作-个人中心首页
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/applyJob")
	public ModelAndView applyJob(HttpServletRequest request) {
		logger.entry("applyJob", "applyJob");
		ModelAndView result = new ModelAndView("h5/enterpriseCenter");
		String jobSeekerId = ServletUtil.getParameterStr(request, "jobSeekerId", "");
		String classId = ServletUtil.getParameterStr(request, "classId", "");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		Map<String, Object> param = new HashMap<>();
		List<Map<String, Object>> recruitmentList = null;
		List<Dict> jobPayList = null;
		String token = sessionUtil.getTokenSession(request);
		if(!"".equals(classId)){

			redisUtil.set(token+"classId", classId);
		}
		Object obj= redisUtil.get(token+"classId");
		if(obj!=null){
			classId=String.valueOf(obj);
		}
		result.addObject("classId", classId);

		int num = 0;
		try {
			
			String studentId = super.getStudentId(request);
			param.put("studentId", studentId);
			Map<String, Object> jobSeekerMap = userJobBasisSeekerService.findJobSeekerMapByMap(param);
			super.getUserBasisInfo(studentId, result);
			String personalInfoFillStatus = "0";
			if (null != jobSeekerMap) {
				personalInfoFillStatus = CommonUtils.getStrValueFromMap(jobSeekerMap, "personalInfoFillStatus", "0");// 完善个人基本信息标识
			}
			if("0".equals(personalInfoFillStatus)) {
				result = new ModelAndView("/h5/basicJob");
				super.getUserBasisInfo(studentId, result);
				result.addObject("educationalRequirementsList", DictUtils.getDictList("educational_requirements"));
				result.addObject("workingLifeList", DictUtils.getDictList("working_life"));
				return result;
			}
			String jobIntensionFillStatus = CommonUtils.getStrValueFromMap(jobSeekerMap, "jobIntensionFillStatus", "0");// 求职意向
			if ("0".equals(jobIntensionFillStatus)) {
				result = new ModelAndView("/h5/jobIntension");
				super.getUserBasisInfo(studentId, result);
				result.addObject("jobSeekerId", jobSeekerId);
				result.addObject("jobPayList", DictUtils.getDictList("job_pay"));
				result.addObject("recruitmentNatureList", DictUtils.getDictList("recruitment_nature"));
				return result;
			}
			String resumeFillStatus = CommonUtils.getStrValueFromMap(jobSeekerMap, "resumeFillStatus", "0");// 经历
			if ("0".equals(resumeFillStatus)) {
				//防止登录时没有
				param.put("userJobBasisId", studentId);
				Map<String,Object> userMap = userJobSeekerService.findJobSeekerMapByMap(param);
				String userJobSeeker = CommonUtils.getStrValueFromMap(userMap,"id","");
				String userJobBasisSeeker = getJobBasisId(request);
				result = new ModelAndView("/h5/resume");
				super.getUserBasisInfo(studentId, result);
				result.addObject("userJobSeeker", userJobSeeker);
				result.addObject("userJobBasisSeeker", userJobBasisSeeker);
				return result;
			}
			param.put("begin", num);
			param.put("endNum", 4);
			recruitmentList = recruitmentPositionService.findListByMap(param);
			dealPostWithDictValue(recruitmentList);
			jobPayList = DictUtils.getDictList("job_pay");
			logger.doInfo("recruitmentList:", recruitmentList);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("recruitmentList", recruitmentList);
		result.addObject("jobPayList", jobPayList);

		return result;
	}

	/**
	 * 刷新简历排名
	 *
	 * @param request
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/auth/refreshResumeRanking")
	public ApiResult<Map<String, Object>> refreshResumeRanking(HttpServletRequest request) {
		logger.entry(request.getRemoteHost(), "refreshResumeRanking");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		try {
			String studentId = super.getStudentId(request);
			logger.entry(ServletUtil.getClientIp(request), "refreshResumeRanking");
			String jobBasisId = getJobBasisId(request);
			UserJobBasisSeekerInfo userJobBasisSeekerInfo = userJobBasisSeekerService.get(jobBasisId);
			Date rfreshDate = userJobBasisSeekerInfo.getRefreshDate();
			if (rfreshDate != null && DateFormatUtils.DateToString(rfreshDate, "yyyy-MM-dd")
					.equals(DateFormatUtils.DateToString(new Date(), "yyyy-MM-dd"))) {
				apiResult.setStatus("-1");
				apiResult.setMessage("今天已经刷新简历了哟。");
				return apiResult;
			}
			Map<String, Object> param = new HashMap<>();
			Date date = new Date();
			//刷新投递简历表更新时间
			param.put("studentId", studentId);
			param.put("updateDate", date);
			resumeDeliveryRecordService.updateByMap(param);
			
			//修改简历基本信息刷新简历时间
			param.put("id", jobBasisId);
			param.put("refreshDate", date);
			param.put("updateDate", date);
			userJobBasisSeekerService.updateByMap(param);
			//修改各个简历基本信息
			param = new HashMap<>();
			param.put("userJobBasisId",jobBasisId);
			param.put("updateDate", date);
			userJobSeekerService.updateByMap(param);

			logger.info(ServletUtil.getClientIp(request));
		} catch (Exception e) {
			apiResult.setStatus(ErrorEnums.SYSTEM_ERROR.getCode());
			apiResult.setMessage(ErrorEnums.SYSTEM_ERROR.getDesc());
			logger.error(JSONObject.toJSONString(apiResult), e);
		}
		return apiResult;
	}

	/**
	 * 保存简历-个人基本信息
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/personalInfoFill")
	@ResponseBody
	public ApiResult<Map<String, Object>> personalInfoFill(HttpServletRequest request) {
		logger.entry("personalInfoFill", "personalInfoFill");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String studentName = ServletUtil.getParameterStr(request, "studentName", "");// 姓名
		String sex = ServletUtil.getParameterStr(request, "sex", "0");// 性别 1:男 2:女
		String birthDate = ServletUtil.getParameterStr(request, "birthDate", "");// 出生年月
		String age = ServletUtil.getParameterStr(request, "age", "0");// 年龄
		String phoneNum = ServletUtil.getParameterStr(request, "phoneNum", "");// 手机
		String standbyPhone = ServletUtil.getParameterStr(request, "standbyPhone", "");// 手机
		String schoolRecord = ServletUtil.getParameterStr(request, "schoolRecord", "");// 学历 1:高中 2:中专 3:大专、4:本科
		String major = ServletUtil.getParameterStr(request, "major", "");// 专业major
		String workOfYeah = ServletUtil.getParameterStr(request, "workOfYeah", "0");// 工作年限`
		String refereesCode = ServletUtil.getParameterStr(request, "refereesCode", "0");// 工作年限`
		String userJobSeekerId = ServletUtil.getParameterStr(request, "userJobSeekerId", "");
		String email = ServletUtil.getParameterStr(request, "email", "");
		String requestType = ServletUtil.getParameterStr(request, "requestType", "");
		Map<String, Object> resultMap = new HashMap<>();
		resultMap.put("userJobSeekerId", userJobSeekerId);
		resultMap.put("requestType", requestType);
		String studentId = super.getStudentId(request);
		UserJobBasisSeekerInfo jobSeekerInfo = new UserJobBasisSeekerInfo();
		jobSeekerInfo.setRealName(studentName);
		jobSeekerInfo.setSex(Integer.valueOf(sex));
		jobSeekerInfo.setBirthDate(birthDate);
		jobSeekerInfo.setAge(Integer.valueOf(age));
		jobSeekerInfo.setMobilePhone(phoneNum);
		jobSeekerInfo.setSpareContactPhone(standbyPhone);
		jobSeekerInfo.setEducation(Integer.valueOf(schoolRecord));
		jobSeekerInfo.setMajor(major);
		jobSeekerInfo.setWorkingLife(Integer.valueOf(workOfYeah));
		jobSeekerInfo.setPersonalInfoFillStatus(1);
		jobSeekerInfo.setEmail(email);
		jobSeekerInfo.setUpdateDate(new Date());
		String jobSeekerId = "";
		try {
			Map<String, Object> param = new HashMap<>();
			param.put("studentId", studentId);
			Map<String, Object> userJobBasisMap = userJobBasisSeekerService.findJobSeekerMapByMap(param);
			if (userJobBasisMap != null) {
				jobSeekerId = CommonUtils.getStrValueFromMap(userJobBasisMap, "id", "");
				jobSeekerInfo.setId(jobSeekerId);
				userJobBasisSeekerService.update(jobSeekerInfo);
			} else {
				jobSeekerId = serialService.generateSerialNum(CreateTypeEnums.CREATE_JOB_SEEKER.getCode(), 7);
				jobSeekerInfo.setId(jobSeekerId);
				jobSeekerInfo.setStudentId(studentId);
				jobSeekerInfo.setReferralCode(refereesCode);
				jobSeekerInfo.setCreateDate(new Date());
				userJobBasisSeekerService.save(jobSeekerInfo);
			}
			apiResult.setInfo(jobSeekerId);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		apiResult.setResult(resultMap);
		return apiResult;
	}

	/**
	 * 保存求职意向信息
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/jobIntension")
	@ResponseBody
	public ApiResult<Map<String, Object>> jobIntension(HttpServletRequest request) {
		logger.entry("jobIntension", "jobIntension");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String calling = ServletUtil.getParameterStr(request, "calling", "");// 期望工作行业
		String job = ServletUtil.getParameterStr(request, "job", "");// 期望工作职业
		String txtWishJobName = ServletUtil.getParameterStr(request, "txtWishJobName", "");// 岗位名称
		String cityvalue = ServletUtil.getParameterStr(request, "cityvalue", "");// 城市名称
		String pay = ServletUtil.getParameterStr(request, "pay", "");// 期望薪资
		String nature = ServletUtil.getParameterStr(request, "nature", "");// 工作性质
		String startdate = ServletUtil.getParameterStr(request, "startdate", "0");// 上岗时间
		String jobSeeker = getJobBasisId(request);
		String resumeCount = ServletUtil.getParameterStr(request, "resumeCount", "");
		String jobId = ServletUtil.getParameterStr(request, "jobId", "");
		String jobSeekerId = "";
		UserJobSeekerInfo userJobSeekerInfo = new UserJobSeekerInfo();
		userJobSeekerInfo.setUpdateDate(new Date());
		userJobSeekerInfo.setExpectedJobIndustry(calling);// 期望工作行业
		userJobSeekerInfo.setExpectedJobCareer(job);// 期望工作职业
		userJobSeekerInfo.setWorkTime(Integer.valueOf(startdate));// 上岗时间
		userJobSeekerInfo.setEnjoyWork(txtWishJobName);// 岗位名称
		userJobSeekerInfo.setExpectedJobArea(cityvalue);// 城市名称
		userJobSeekerInfo.setExpectedJobPay(pay);// 期望薪资
		userJobSeekerInfo.setExpectedJobNature(Integer.valueOf(nature));// 工作性质
		try {
			if (StringUtil.isNotEmpty(jobId)) {
				jobSeekerId = jobId;
				userJobSeekerInfo.setId(jobId);
				userJobSeekerService.update(userJobSeekerInfo);
			} else {
				String studentId = getStudentId(request);
//				List<Map<String, Object>> userJobList = userJobBasisSeekerService.findListByStudentId(studentId);
				String jobBasisId = getJobBasisId(request);
				Map<String, Object> param = new HashMap<>();
				param.put("userJobBasisId", jobBasisId);
				List<Map<String, Object>> userJobList = userJobSeekerService.findListByMap(param);
				if(userJobList.size()>2){
					apiResult.setStatus("0000001");
					apiResult.setMessage("创建简历已经超过份数限制！");
					return apiResult;
				}
				//防止重复提交
				int resume_count;
				if("".equals(resumeCount)){
					resume_count = 1;
				}else{
					resume_count = Integer.parseInt(resumeCount);
				}
				if(resume_count != userJobList.size() ){
					jobSeekerId = serialService.generateSerialNum(CreateTypeEnums.CREATE_JOB_SEEKER.getCode(), 7);
					userJobSeekerInfo.setId(jobSeekerId);
					userJobSeekerInfo.setResumeName("我的简历1");
					userJobSeekerInfo.setDefaultFlag(1);
					if ("2".equals(resumeCount)) {
						userJobSeekerInfo.setResumeName("我的简历2");
						userJobSeekerInfo.setDefaultFlag(0);
					} else if ("1".equals(resumeCount)) {
						userJobSeekerInfo.setResumeName("我的简历3");
						userJobSeekerInfo.setDefaultFlag(0);
					}
					userJobSeekerInfo.setCreateDate(new Date());
					userJobSeekerInfo.setUserJobBasisId(jobSeeker);// 更新主键
					userJobSeekerService.save(userJobSeekerInfo);
					UserJobBasisSeekerInfo userJobBasisSeekerInfo = new UserJobBasisSeekerInfo();
					userJobBasisSeekerInfo.setId(jobSeeker);
					userJobBasisSeekerInfo.setUpdateDate(new Date());
					userJobBasisSeekerInfo.setJobIntensionFillStatus(1);
					userJobBasisSeekerService.update(userJobBasisSeekerInfo);
				}
			}
			Map<String, Object> map = new HashMap<>();
			map.put("userJobSeeker", jobSeekerId);
			map.put("userJobBasisSeeker", jobSeeker);
			apiResult.setResult(map);
			logger.info(apiResult);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		return apiResult;
	}

	/**
	 * 保存简历-个人介绍
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping("/auth/resume")
	@ResponseBody
	public ApiResult<Map<String, Object>> resume(HttpServletRequest request) {
		logger.entry("resume", "resume");


		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String learningExperience = ServletUtil.getParameterStr(request, "learningExperience", "");// 学习经历
		String workingExperience = ServletUtil.getParameterStr(request, "workingExperience", "");// 工作经历
		String personalSpecialty = ServletUtil.getParameterStr(request, "personalSpecialty", "");// 个人特长
		String jobRequirements = ServletUtil.getParameterStr(request, "jobRequirements", "");// 对招聘公司的详细要求
		String selfIntroduction = ServletUtil.getParameterStr(request, "selfIntroduction", "");// 自我介绍
		String userJobSeeker = ServletUtil.getParameterStr(request, "userJobSeeker", "");
		String resumeId = ServletUtil.getParameterStr(request, "resumeId", "");
		String userJobBasisSeeker = getJobBasisId(request);
		ResumeInfo resumeInfo = new ResumeInfo();
		resumeInfo.setUserJobSeekerId(userJobSeeker);
		resumeInfo.setLearningExperience(learningExperience.replaceAll("&quot;", "\""));
		resumeInfo.setWorkExperience(workingExperience.replaceAll("&quot;", "\""));
		resumeInfo.setSelfIntroduction(selfIntroduction.replaceAll("&quot;", "\""));
		resumeInfo.setPersonalSpecialty(personalSpecialty);
		resumeInfo.setJobRequirements(jobRequirements);
		resumeInfo.setUpdateDate(new Date());
		try {
			String indexFlag = "0";
			//如果存在直接修改
			if(StringUtils.isNotBlank(resumeId)){
				resumeInfo.setId(resumeId);
				resumeService.update(resumeInfo);
				//证书检查更新
				String token = sessionUtil.getTokenSession(request);
				Object obj= redisUtil.get(token+"classId");
				if(obj!=null){
					String	classId=String.valueOf(obj);
					if(!"".equals(classId)){
						if(CheckResumeInfo(resumeInfo)){
							String studentId = super.getStudentId(request);
							MxCertificateInfo mxCertificateInfo = new MxCertificateInfo();
							mxCertificateInfo.setClassId(classId);
							mxCertificateInfo.setStudentId(studentId);
							MxCertificateInfo certificateInfo = mxCertificateInfoService.getByClassStudent(mxCertificateInfo);
							certificateInfo.setCheckResume("1");//更新证书简历状态
							if("2".equals(certificateInfo.getCheckInfo())&&"1".equals(certificateInfo.getCheckScore())){
								certificateInfo.setState(1);//更新证书简历状态
							}
							mxCertificateInfoService.update(certificateInfo);
						}
					}
				}

			}else{
				Map<String,Object> findParamMap = new HashMap<>();
				//如果不存在 先验证有没有简历详情 没有保存 有则更改 防止页面返回重复提交
				findParamMap.put("jobId",userJobSeeker);
				Map<String,Object> findMap = resumeService.findResumeMapByMap(findParamMap);
				//判断是否存在
				if(findMap==null || findMap.isEmpty()){
					resumeId = serialService.generateSerialNum(
							CreateTypeEnums.CREATE_RESUME.getCode(), 7);
					resumeInfo.setId(resumeId);
					resumeInfo.setUserJobSeekerId(userJobSeeker);
					resumeInfo.setCreateDate(new Date());
					resumeService.save(resumeInfo);
					//当前无简历 创建后跳转到个人首页
					UserJobBasisSeekerInfo userJobBasisSeekerInfoFind = userJobBasisSeekerService.get(userJobBasisSeeker);
					if(userJobBasisSeekerInfoFind.getResumeFillStatus() == 0){
						indexFlag = "1";
						UserJobBasisSeekerInfo userJobBasisSeekerInfo = new UserJobBasisSeekerInfo();
						userJobBasisSeekerInfo.setId(userJobBasisSeeker);
						userJobBasisSeekerInfo.setUpdateDate(new Date());
						userJobBasisSeekerInfo.setResumeFillStatus(1);
						userJobBasisSeekerService.update(userJobBasisSeekerInfo);
					}
				}else {
					resumeId = CommonUtils.getStrValueFromMap(findMap,"id","");
					resumeInfo.setId(resumeId);
					resumeService.update(resumeInfo);
				}
			}
			Map<String,Object> retMap = new HashMap<>();
			retMap.put("indexFlag",indexFlag);
			apiResult.setResult(retMap);
			logger.info(apiResult);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		return apiResult;
	}

	private Boolean CheckResumeInfo(ResumeInfo resumeInfo) {
		Boolean b = new Boolean(false);
		try {
			Map<String, Object> param = new HashMap<>();
			//param.put("studentId", studentId);
			//Map<String, Object> userJobBasisSeekerInfo = userJobBasisSeekerService.findJobSeekerMapByMap(param);

			if (resumeInfo != null) {
				Map<String, Object> map = new HashMap<>();
				//map.put("jobId", studentId);
				//Map<String, Object> resumeInfo = resumeService.findResumeMapByMap(map);
				String work =resumeInfo.getWorkExperience();
				String learn = resumeInfo.getLearningExperience();
				String personal = resumeInfo.getPersonalSpecialty();
				String introduction = resumeInfo.getSelfIntroduction();
				String jobs = resumeInfo.getJobRequirements();
				if ((!work.equals("[]")) && (!learn.equals("[]")) && personal.length() > 0 && introduction.length() > 0 && jobs.length() > 0) {
					b = true;
				}
			}
		} catch (Exception e) {

		}
		//测试用暂时设置为true
		//b = true;
		return b;
	}

	/**
	 * 我的简历列表
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/myResumeList")
	public ModelAndView myResumeList(HttpServletRequest request) {
		logger.entry("myResume", "myResume");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		ModelAndView result = new ModelAndView("/h5/myResumeList");
		Map<String, Object> param = new HashMap<>();
		List<Map<String, Object>> userJobList = null;
		int count = 3;
		String userJobBasisId = "";
		try {

			String studentId = super.getStudentId(request);
			param.put("studentId", studentId);
			super.getUserBasisInfo(studentId, result);
			userJobList = userJobBasisSeekerService.findListByStudentId(studentId);
			if (userJobList != null && userJobList.size() > 0) {
				count -= userJobList.size();
				userJobBasisId = CommonUtils.getStrValueFromMap(userJobList.get(0), "userJobBasisId", "");
			}

		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("userJobList", userJobList);
		result.addObject("count", count);
		result.addObject("userJobBasisId", userJobBasisId);
		return result;
	}

	/**
	 * 新建简历
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/createResume")
	public ModelAndView createResume(HttpServletRequest request) {
		logger.entry("createResume", "createResume");
		String createType = ServletUtil.getParameterStr(request, "createType", "");
		String resumeCount = ServletUtil.getParameterStr(request, "resumeCount", "2");
		String studentId = super.getStudentId(request);
		Map<String, Object> param = new HashMap<>();
		param.put("studentId", studentId);
		Map<String, Object> userJobBasisMap = userJobBasisSeekerService.findJobSeekerMapByMap(param);
		String userJobBasisId = CommonUtils.getStrValueFromMap(userJobBasisMap, "id", "");
		ModelAndView result = new ModelAndView("/h5/jobIntension");
		result.addObject("jobSeekerId", userJobBasisId);
		result.addObject("type", "createResume");
		result.addObject("resumeCount", resumeCount);
		result.addObject("jobPayList", DictUtils.getDictList("job_pay"));
		result.addObject("recruitmentNatureList", DictUtils.getDictList("recruitment_nature"));
		getUserMapByToken(request, result);
		// 创建简历
		if ("resume".equals(createType)) {
			String userJobSeeker = ServletUtil.getParameterStr(request, "userJobSeeker", "");
			String userJobBasisSeeker = ServletUtil.getParameterStr(request, "userJobBasisSeeker", "");
			result = new ModelAndView("/h5/resume");
			super.getUserBasisInfo(studentId, result);
			result.addObject("userJobSeeker", userJobSeeker);
			result.addObject("jobId", userJobSeeker);
			result.addObject("userJobBasisSeeker", userJobBasisSeeker);
			return result;
		}
		return result;
	}

	/**
	 * 更新默认简历
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/updateDefaultResume")
	@ResponseBody
	public ApiResult<Map<String, Object>> updateDefaultResume(HttpServletRequest request) {
		logger.entry("updateDefaultResume", "updateDefaultResume");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String userJobId = ServletUtil.getParameterStr(request, "userJobId", "");
		String userJobBasisId = ServletUtil.getParameterStr(request, "userJobBasisId", "");
		try {
			Map<String, Object> param = new HashMap<>();
			param.put("userJobBasisId", userJobBasisId);
			param.put("defaultFlag", "0");
			userJobSeekerService.updateByMap(param);
			param.remove("userJobBasisId");
			param.put("userJobId", userJobId);
			param.put("defaultFlag", "1");
			param.put("updateDate", new Date());
			userJobSeekerService.updateByMap(param);
			logger.info("updateDefaultResume");
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		return apiResult;
	}

	/**
	 * 我的简历详细信息
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/myResume")
	public ModelAndView myResume(HttpServletRequest request) {
		logger.entry("myResume", "myResume");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		ModelAndView result = new ModelAndView("/h5/myResume");
		String jobId = ServletUtil.getParameterStr(request, "jobId", "");
		Map<String, Object> userJobBasisMap = null;
		Map<String, Object> userJobMap = null;
		Map<String, Object> resumeMap = null;
		List learningExperienceList = null;
		List workExperienceList = null;
		String workTime = "";
		String expectedJobNature = "";
		String enjoyWork = "";
		String userJobId = "";
		Map<String, Object> param = new HashMap<>();
		String expectedJobIndustryName = "";
		String expectedJobCareerName = "";
		String expectedJobAreaName = "";
		String expectedJobPayVal = "";
		String workingLife = "";
		String educationalRequirements = "";
		try {
			String studentId = super.getStudentId(request);
			param.put("studentId", studentId);
			// 用户基本信息
			userJobBasisMap = userJobBasisSeekerService.findJobSeekerMapByMap(param);
			workingLife = DictUtils.getDictLabel(CommonUtils.getStrValueFromMap(userJobBasisMap, "workingLife", ""), "working_life", "");
			educationalRequirements = DictUtils.getDictLabel(CommonUtils.getStrValueFromMap(userJobBasisMap, "education", ""), "educational_requirements", "");
			// 求职意向
			param.remove("studentId");
			param.put("jobId", jobId);
			userJobMap = userJobSeekerService.findJobSeekerMapByMap(param);
			userJobId = CommonUtils.getStrValueFromMap(userJobMap, "id", "");
			// 期望工作行业
			String expectedJobIndustry = CommonUtils.getStrValueFromMap(userJobMap, "expectedJobIndustry", "");
			String[] expectedJobIndustrys = expectedJobIndustry.split(",");
			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < expectedJobIndustrys.length; i++) {
				String jobIndustryId = expectedJobIndustrys[i];
				Map<String, Object> jobIndustryMap = cacheService.getPlace(jobIndustryId);
				String jobIndustryName = CommonUtils.getStrValueFromMap(jobIndustryMap, "name", "");
				sb.append(jobIndustryName);
				if (i != expectedJobIndustrys.length - 1) {
					sb.append(",");
				}
			}
			expectedJobIndustryName = sb.toString();

			// 期望工作职业 多个也逗号隔开
			String expectedJobCareer = CommonUtils.getStrValueFromMap(userJobMap, "expectedJobCareer", "");
			String[] expectedJobCareers = expectedJobCareer.split(",");
			sb = new StringBuffer();
			for (int i = 0; i < expectedJobCareers.length; i++) {
				String jobCareersId = expectedJobCareers[i];
				Map<String, Object> jobCareersMap = cacheService.getPlace(jobCareersId);
				String jobCareersName = CommonUtils.getStrValueFromMap(jobCareersMap, "name", "");
				sb.append(jobCareersName);
				if (i != expectedJobCareers.length - 1) {
					sb.append(",");
				}
			}
			expectedJobCareerName = sb.toString();

			// 工作地区
			String expectedJobArea = CommonUtils.getStrValueFromMap(userJobMap, "expectedJobArea", "");
			String[] expectedJobAreas = expectedJobArea.split(",");
			sb = new StringBuffer();
			for (int i = 0; i < expectedJobAreas.length; i++) {
				String jobAreasId = expectedJobAreas[i];
				Map<String, Object> jobAreasMap = cacheService.getPlace(jobAreasId);
				String jobAreasName = CommonUtils.getStrValueFromMap(jobAreasMap, "name", "");
				sb.append(jobAreasName);
				if (i != expectedJobAreas.length - 1) {
					sb.append("-");
				}
			}
			expectedJobAreaName = sb.toString();

			// 工作薪酬
			String expectedJobPay = CommonUtils.getStrValueFromMap(userJobMap, "expectedJobPay", "");
			Map<String, Object> dictParam = new HashMap<>();
			dictParam.put("type", "job_pay");
			dictParam.put("value", expectedJobPay);
			Map<String, Object> dictMap = sysDictServicel.findMapByMap(dictParam);
			expectedJobPayVal = CommonUtils.getStrValueFromMap(dictMap, "label", "");

			// 简历信息
			param.put("jobId", jobId);
			resumeMap = resumeService.findResumeMapByMap(param);
			if(resumeMap!=null){
				String learningExperience = CommonUtils.getStrValueFromMap(resumeMap, "learningExperience", "");
				String workExperience = CommonUtils.getStrValueFromMap(resumeMap, "workExperience", "");
				workTime = CommonUtils.getStrValueFromMap(resumeMap, "workTime", "");
				expectedJobNature = CommonUtils.getStrValueFromMap(resumeMap, "expectedJobNature", "");
				learningExperienceList = JSONObject.parseArray(learningExperience, Map.class);
				workExperienceList = JSONObject.parseArray(workExperience, Map.class);
				enjoyWork = CommonUtils.getStrValueFromMap(resumeMap, "enjoyWork", "");
			}
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("userJobBasisMap", userJobBasisMap);
		result.addObject("userJobMap", userJobMap);
		result.addObject("resumeMap", resumeMap);
		result.addObject("learningExperience", learningExperienceList);
		result.addObject("workExperience", workExperienceList);
		if (StringUtils.isNotBlank(workTime) && WorkTimeEnums.getMap().get(workTime) != null) {
			result.addObject("workTime", WorkTimeEnums.getMap().get(workTime).getDesc());
		}
		if (StringUtils.isNotBlank(expectedJobNature) && ExpectedJobNature.getMap().get(expectedJobNature) != null) {
			result.addObject("expectedJobNature", ExpectedJobNature.getMap().get(expectedJobNature).getDesc());
		}
		result.addObject("enjoyWork", enjoyWork);
		result.addObject("jobId", jobId);
		result.addObject("userJobId", userJobId);
		result.addObject("expectedJobIndustryName", expectedJobIndustryName);
		result.addObject("expectedJobCareerName", expectedJobCareerName);
		result.addObject("expectedJobAreaName", expectedJobAreaName);
		result.addObject("expectedJobPayVal", expectedJobPayVal);
		result.addObject("workingLife", workingLife);
		result.addObject("educationalRequirements", educationalRequirements);
		getUserMapByToken(request, result);
		return result;
	}

	/**
	 * 搜索职位
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/searchJob")
	public ModelAndView searchJob(HttpServletRequest request) {
		logger.entry("searchJob", "searchJob");
		String calling = ServletUtil.getParameterStr(request, "calling", "");
		String job = ServletUtil.getParameterStr(request, "job", "");
		String cityvalue = ServletUtil.getParameterStr(request, "cityvalue", "");
		String jobPay = ServletUtil.getParameterStr(request, "jobPay", "");
		String keyword = ServletUtil.getParameterStr(request, "keyword", "");
		String type = ServletUtil.getParameterStr(request, "type", "");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		ModelAndView result = null;
		if("enterprise".equals(type)) {
			result = new ModelAndView("/h5/enterpriseCenter");
		}else {
			result = new ModelAndView("/h5/personnelIndex");
		}
		List<Map<String, Object>> positionList = null;
		Map<String, Object> param = new HashMap<>();
		int num = 0;
		try {
			StringBuilder sb = new StringBuilder();
			if (!"".equals(calling)) {
				String[] callings = calling.split(",");
				for (int i = 0; i < callings.length; i++) {
					int a = i + 1;
					param.put("expectedJobIndustry" + a, "%" + callings[i] + "%");
					String expectedJobIndustryId = callings[i];
					Map<String, Object> jobCareersMap = cacheService.getPlace(expectedJobIndustryId);
					String expectedJobIndustryVal = CommonUtils.getStrValueFromMap(jobCareersMap, "name", "");
					sb.append(expectedJobIndustryVal);
					if (i != callings.length - 1) {
						sb.append(",");
					}
				}
				String expectedJobIndustryName = sb.toString();
				result.addObject("expectedJobIndustryName", expectedJobIndustryName);
			}
			if (!"".equals(job)) {
				String[] jobs = job.split(",");
				sb = new StringBuilder();
				for (int i = 0; i < jobs.length; i++) {
					int a = i + 1;
					param.put("job" + a, "%" + jobs[i] + "%");
					String jobCareersId = jobs[i];
					Map<String, Object> jobCareersMap = cacheService.getPlace(jobCareersId);
					String jobCareersName = CommonUtils.getStrValueFromMap(jobCareersMap, "name", "");
					sb.append(jobCareersName);
					if (i != jobs.length - 1) {
						sb.append(",");
					}
				}
				String jobCareersName = sb.toString();
				result.addObject("jobCareersName", jobCareersName);
			}
			if (!"".equals(cityvalue)) {
				String[] cityvalues = cityvalue.split(",");
				param.put("cityvalueName", "%"+cityvalues[cityvalues.length - 1]+"%");
				// 工作地区
				sb = new StringBuilder();
				for (int i = 0; i < cityvalues.length; i++) {
					String jobAreasId = cityvalues[i];
					Map<String, Object> jobAreasMap = cacheService.getPlace(jobAreasId);
					String jobAreasVal = CommonUtils.getStrValueFromMap(jobAreasMap, "name", "");
					sb.append(jobAreasVal);
					if (i != cityvalues.length - 1) {
						sb.append(",");
					}
				}
				String jobAreasName = sb.toString();
				result.addObject("jobAreasName", jobAreasName);
				result.addObject("cityvalue", cityvalue);
			}
			param.put("jobPay", jobPay);
			param.put("keyword", "%" + keyword + "%");
			param.put("begin", num);
			param.put("endNum", 6);
			positionList = recruitmentPositionService.findListByMap(param);
			dealPostWithDictValue(positionList);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("jobPayList", DictUtils.getDictList("job_pay"));

		result.addObject("calling", calling);
		result.addObject("keyword", keyword);
		result.addObject("job", job);
		result.addObject("cityvalue", cityvalue);
		result.addObject("jobPay", jobPay);
		result.addObject("keyword", keyword);
		getUserMapByToken(request, result);
		result.addObject("recruitmentList", positionList);
		return result;
	}

	@ResponseBody
	@RequestMapping(value = "/public/toWorkDetails")
	public Map<String, Object> toWorkDetails(HttpServletRequest request){
		Map<String, Object> retMap = new HashMap<>();
		Map<String, Object> param = new HashMap<>();
		String positionId = ServletUtil.getParameterStr(request, "positionId", "");
		String type = ServletUtil.getParameterStr(request, "type", "");
		param.put("positionId", positionId);
		param.put("begin", 0);
		Map<String, Object> positionMap = recruitmentPositionService.findMapByMap(param);
		int staus = 1;
		if(positionMap == null){
			staus = 0;
		}
		retMap.put("status", staus);
		return retMap;
	}

	/**
	 * 职位详细信息
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/workDetails")
	public ModelAndView workDetails(HttpServletRequest request) {
		logger.entry("workDetails", "workDetails");
		ModelAndView result = new ModelAndView("/h5/workDetails");
		String positionId = ServletUtil.getParameterStr(request, "positionId", "");
		String type = ServletUtil.getParameterStr(request, "type", "");
		Map<String, Object> positionMap = null;
		String educationalRequirementsName = "";
		Map<String, Object> param = new HashMap<>();
		String studentId = super.getStudentId(request);
		param.put("studentId", studentId);
		Map<String, Object> jobSeekerMap = userJobBasisSeekerService.findJobSeekerMapByMap(param);
		super.getUserBasisInfo(studentId, result);
		String personalInfoFillStatus = "0";
		if (null != jobSeekerMap) {
			personalInfoFillStatus = CommonUtils.getStrValueFromMap(jobSeekerMap, "personalInfoFillStatus", "0");// 完善个人基本信息标识
		}
		if ("0".equals(personalInfoFillStatus)) {
			result = new ModelAndView("/h5/basicJob");
			super.getUserBasisInfo(studentId, result);
			result.addObject("educationalRequirementsList", DictUtils.getDictList("educational_requirements"));
			result.addObject("workingLifeList", DictUtils.getDictList("working_life"));
			return result;
		}
		param = new HashMap<>();
		param.put("positionId", positionId);
		param.put("begin", 0);
		positionMap = recruitmentPositionService.findMapByMap(param);
		dealPostMap(positionMap);
		result.addObject("positionMap", positionMap);
		result.addObject("educationalRequirements", educationalRequirementsName);
		result.addObject("positionId", positionId);
		result.addObject("type", type);
		getUserMapByToken(request, result);
		return result;
	}

	/**
	 * 帮我找工作
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/helpMeFindANewJob")
	public ModelAndView helpMeFindANewJob(HttpServletRequest request) {
		logger.entry("helpMeFindANewJob", "helpMeFindANewJob");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		ModelAndView result = new ModelAndView("/h5/helpMeFindANewJobList");
		List<Map<String, Object>> newPositionList = new ArrayList<>();
		String studentId = super.getStudentId(request);
		try {
			String jobBasisId = getJobBasisId(request);
			Map<String, Object> param = new HashMap<>();
			param.put("userJobBasisId", jobBasisId);
			param.put("defaultFlag", 1);
			Map<String, Object> userSeekerMap = userJobSeekerService.findJobSeekerMapByMap(param);
			param = new HashMap<>();
			// 期望工作行业
			String expectedJobIndustry = CommonUtils.getStrValueFromMap(userSeekerMap, "expectedJobIndustry", "");
			String[] expectedJobIndustrys = expectedJobIndustry.split(",");
			for (int i = 0; i < expectedJobIndustrys.length; i++) {
				int a = i + 1;
				param.put("expectedJobIndustry" + a, "%" + expectedJobIndustrys[i] + "%");
			}
			// 期望工作职业
			// String expectedJobCareer = CommonUtils.getStrValueFromMap(userSeekerMap,
			// "expectedJobCareer", "");
			// String[] expectedJobCareers = expectedJobCareer.split(",");
			// for(int i = 0; i < expectedJobCareers.length; i++) {
			// int a = i + 1;
			// param.put("expectedJobCareer"+a, "%"+expectedJobCareers[i]+"%");
			// }
			// 期望工作的地区
			String expectedJobArea = CommonUtils.getStrValueFromMap(userSeekerMap, "expectedJobArea", "");
			String[] expectedJobAreas = expectedJobArea.split(",");
			String jobArea = expectedJobAreas[expectedJobAreas.length - 1];
			param.put("expectedJobArea", "%" + jobArea + "%");
			// 期望工作薪酬
			String expectedJobPay = CommonUtils.getStrValueFromMap(userSeekerMap, "expectedJobPay", "");
			// 工作性质
			// String expectedJobNature = CommonUtils.getStrValueFromMap(userSeekerMap,
			// "expectedJobNature", "");
			param.put("expectedJobPay", expectedJobPay);
			// param.put("expectedJobNature", expectedJobNature);
			List<Map<String, Object>> positionList = recruitmentPositionService.helpMeFindANewJob(param);
			for (Map<String, Object> map : positionList) {
				String jobPay = CommonUtils.getStrValueFromMap(map, "jobPay", "");
				String jobPayName = DictUtils.getDictLabel(jobPay, "job_pay", "");
				map.put("jobPayName", jobPayName);
				newPositionList.add(map);
			}
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		super.getUserBasisInfo(studentId, result);
		result.addObject("position", newPositionList);
		return result;
	}

	/**
	 * 选择简历列表
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/sendResumeList")
	public ModelAndView sendResumeList(HttpServletRequest request) {
		logger.entry("sendResumeList", "sendResumeList");
		ModelAndView result = new ModelAndView("/h5/sendResumeList");
		String companyId = ServletUtil.getParameterStr(request, "companyId", "");
		String post = ServletUtil.getParameterStr(request, "post", "");
		String postId = ServletUtil.getParameterStr(request, "postId", "");
		String positionId = ServletUtil.getParameterStr(request, "positionId", "");
		String type = ServletUtil.getParameterStr(request, "type", "");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		List<Map<String, Object>> userJobList = null;
		String userJobBasisId = "";
		int count = 18;
		try {
			Map<String, Object> param = new HashMap<>();
			String studentId = super.getStudentId(request);
			super.getUserBasisInfo(studentId, result);
			userJobBasisId = getJobBasisId(request);
			userJobList = userJobBasisSeekerService.findListByStudentId(studentId);
			param.put("studentId", studentId);
			param.put("jobBasisId", userJobBasisId);// 投递类型 1:求职者主动投递
			param.put("deliveryType", "1");// 投递类型 1:求职者主动投递
			param.put("createDate", DateFormatUtils.DateToString(new Date(), "yyyy-MM-dd"));
			List<Map<String, Object>> deliveryList = resumeDeliveryRecordService.findListAllByMap(param);
			if (deliveryList != null && deliveryList.size() > 0) {
				count = 18 - deliveryList.size();
			}
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("companyId", companyId);
		result.addObject("post", post);
		result.addObject("userJobBasisId", userJobBasisId);
		result.addObject("userJobList", userJobList);
		result.addObject("postId", postId);
		result.addObject("count", count);
		result.addObject("positionId", positionId);
		result.addObject("type", type);
		return result;
	}

	/**
	 * 投递简历
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/sendResume")
	@ResponseBody
	public ApiResult<Map<String, Object>> sendResume(HttpServletRequest request) {
		logger.entry("sendResume", "sendResume");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String companyId = ServletUtil.getParameterStr(request, "companyId", "");
		String userJobSeekerId = ServletUtil.getParameterStr(request, "userJobSeekerId", "");
		String positionId = ServletUtil.getParameterStr(request, "positionId", "");
		String studentId = super.getStudentId(request);
		try {
			Map<String, Object> param = new HashMap<>();
			param.put("positionId", positionId);
			param.put("begin", 0);
			Map<String, Object> positionMap = recruitmentPositionService.findMapByMap(param);
			String status = positionMap==null? "": (positionMap.get("status") == null ? "":positionMap.get("status").toString());
			if("2".equals(status) || StringUtils.isEmpty(status)){
				apiResult.setStatus("1");
				apiResult.setMessage("该职位已关闭");
				return apiResult;

			}
			param = new HashMap<>();
			param.put("id", userJobSeekerId);
			Map<String, Object> userJobSeekerMap = userJobSeekerService.findJobSeekerMapByMap(param);
			if(userJobSeekerMap == null){
				apiResult.setStatus("3");
				apiResult.setMessage("该条简历已被删除,请刷新页面后再次投递");
				return apiResult;
			}
			param = new HashMap<>();
			param.put("studentId", studentId);
			param.put("jobSeekerId", userJobSeekerId);// 投递类型 1:求职者主动投递
			param.put("deliveryType", "1");// 投递类型 1:求职者主动投递
			param.put("createDate", DateFormatUtils.DateToString(new Date(), "yyyy-MM-dd"));
			List<Map<String, Object>> deliveryList = resumeDeliveryRecordService.findListAllByMap(param);
			if(deliveryList!=null && deliveryList.size()>=18){
				apiResult.setStatus("2");
				apiResult.setMessage("每天只能投递18份简历");
				return apiResult;
			}

			param = new HashMap<>();
			param.put("jobId", userJobSeekerId);
			Map<String, Object> resumeMap = resumeService.findResumeMapByMap(param);
			String resumeId = CommonUtils.getStrValueFromMap(resumeMap, "id", "");
			String deliveryId = serialService.generateSerialNum(CreateTypeEnums.CREATE_DELIVERY.getCode(), 7);
			ResumeDeliveryRecordInfo recordInfo = new ResumeDeliveryRecordInfo();
			recordInfo.setId(deliveryId);
			recordInfo.setCompanyId(companyId);// 公司Id
			recordInfo.setResumeId(resumeId);// 简历ID
			recordInfo.setPositionId(positionId);// 职位
			recordInfo.setJobSeekerId(userJobSeekerId);// 求职者Id
			recordInfo.setDeliveryType(1);// 投递类型 1:求职者主动投递 2:招聘公司付费下载
			recordInfo.setIsCharge(0);// 是否收费 0:免费 1:收费
			recordInfo.setCreateDate(new Date());
			recordInfo.setUpdateDate(new Date());
			recordInfo.setDelFlag(0);
			recordInfo.setStudentId(studentId);
			resumeDeliveryRecordService.save(recordInfo);
			logger.info(apiResult);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		return apiResult;
	}

	/**
	 * 投递简历列表
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/auth/submittedResumeList")
	public ModelAndView submittedResumeList(HttpServletRequest request) {
		logger.entry("submittedResumeList", "submittedResumeList");
		ModelAndView result = new ModelAndView("/h5/sendResumeManage");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		int num = 0;
		try {
			String jobBasisId = getJobBasisId(request);
			Map<String, Object> param = new HashMap<>();
			param.put("begin", num);
			param.put("jobBasisId", jobBasisId);
			param.put("endNum", pageSize);
			param.put("limit", "limit");
			param.put("resumeDelFlag", "1");
			List<Map<String, Object>> deliveryList = resumeDeliveryRecordService.findListByMap(param);
			formatDeliveryRecord(deliveryList);
			result.addObject("submittedResumeList", deliveryList);
			logger.info(apiResult);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		getUserMapByToken(request, result);
		return result;
	}

	private void formatDeliveryRecord(List<Map<String, Object>> dataList) {
		for (Map<String, Object> map : dataList) {
			String sex = CommonUtils.getStrValueFromMap(map, "sex", "");
			map.put("sexName", DictUtils.getDictLabel(sex, "sex", ""));

			String education = CommonUtils.getStrValueFromMap(map, "educationalRequirements", "");
			map.put("educationName", DictUtils.getDictLabel(education, "educational_requirements", ""));

			String workingLife = CommonUtils.getStrValueFromMap(map, "workingLife", "");
			map.put("workingLifeName", DictUtils.getDictLabel(workingLife, "working_life", ""));
			if (map.get("createDate") != null) {
				Date createDate = (Date) map.get("createDate");
				map.put("createDateValue", DateFormatUtils.DateToString(createDate, DateStyle.YYYY_MM_DD));
			}
			String expectedJobIndustry = CommonUtils.getStrValueFromMap(map, "expectedJobIndustry", "");
			String[] industryIds = expectedJobIndustry.split(",");
			StringBuffer industryName = new StringBuffer();
			int i = 1;
			for (String industryId : industryIds) {
				Map<String, Object> placeMap = cacheService.getPlace(industryId);
				if (placeMap != null && placeMap.containsKey("name")) {
					industryName.append(placeMap.get("name"));
					if (i < industryIds.length) {
						industryName.append(",");
					}
				}
				i++;
			}
			map.put("expectedJobIndustryName", industryName);

			String recruitmentNature = CommonUtils.getStrValueFromMap(map, "recruitmentNature", "");
			map.put("expectedJobNatureName", DictUtils.getDictLabel(recruitmentNature, "recruitment_nature", ""));

			String workPlace = CommonUtils.getStrValueFromMap(map, "workPlace", "");
			String[] placeIds = workPlace.split(",");
			StringBuffer workPlaceName = new StringBuffer();
			i = 1;
			for (String placeId : placeIds) {
				Map<String, Object> placeMap = cacheService.getPlace(placeId);
				if (placeMap != null && placeMap.containsKey("name")) {
					workPlaceName.append(placeMap.get("name"));
					if (i < placeIds.length) {
						workPlaceName.append(",");
					}
				}
				i++;
			}
			map.put("expectedJobAreaName", workPlaceName);
			String jobPay = CommonUtils.getStrValueFromMap(map, "jobPay", "");
			map.put("jobPayName", DictUtils.getDictLabel(jobPay, "job_pay", ""));

		}
	}

	@RequestMapping(value = "/auth/deleteResume")
	@ResponseBody
	public ApiResult<Map<String, Object>> deleteResume(HttpServletRequest request) {
		logger.entry("deleteResume", "deleteResume");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String deliveryId = ServletUtil.getParameterStr(request, "deliveryId", "");
		Map<String, Object> param = new HashMap<>();
		try {
			param.put("updateDate", new Date());
			param.put("deliveryId", deliveryId);
			param.put("resumeDelFlag", 1);
			resumeDeliveryRecordService.updateByMap(param);
			logger.info(apiResult);
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		return apiResult;
	}

	@RequestMapping(value = "/auth/toUserDetailedInfo")
	public ModelAndView toUserDetailedInfo(HttpServletRequest request) {
		logger.entry("toUserDetailedInfo", "toUserDetailedInfo");
		ApiResult<Map<String, Object>> apiResult = new ApiResult<>();
		String type = ServletUtil.getParameterStr(request, "type", "");
		String userJobSeekerId = ServletUtil.getParameterStr(request, "userJobSeekerId", "");
		Map<String, Object> userMap = null;
		ModelAndView result = null;
		String expectedJobIndustryName = "";
		String expectedJobCareerName = "";
		String expectedJobAreaName = "";
		Map<String, Object> dictParam = new HashMap<>();
		String studentId = super.getStudentId(request);

		try {
			Map<String, Object> param = new HashMap<>();
			if ("userBasisInfo".equals(type)) {
				// 学历要求
				dictParam.put("type", "educational_requirements");
				List<Map<String, Object>> educationalRequirementsList = sysDictServicel.findListByMap(dictParam);
				// 工作年限
				dictParam.put("type", "working_life");
				List<Map<String, Object>> workingLifeList = sysDictServicel.findListByMap(dictParam);
				param.put("studentId", studentId);
				userMap = userJobBasisSeekerService.findJobSeekerMapByMap(param);
				result = new ModelAndView("/h5/basicJob");
				result.addObject("educationalRequirementsList", educationalRequirementsList);
				result.addObject("workingLifeList", workingLifeList);
				result.addObject("userJobSeekerId", userJobSeekerId);
				result.addObject("type", "toUserDetailedInfo");
				result.addObject("isCheck", "no");
			} else if ("userSeekerInfo".equals(type)) {
				param.put("jobId", userJobSeekerId);
				userMap = userJobSeekerService.findJobSeekerMapByMap(param);
				// 期望工作行业
				String expectedJobIndustry = CommonUtils.getStrValueFromMap(userMap, "expectedJobIndustry", "");
				String[] expectedJobIndustrys = expectedJobIndustry.split(",");
				StringBuffer sb = new StringBuffer();
				for (int i = 0; i < expectedJobIndustrys.length; i++) {
					String jobIndustryId = expectedJobIndustrys[i];
					Map<String, Object> jobIndustryMap = cacheService.getPlace(jobIndustryId);
					String jobIndustryName = CommonUtils.getStrValueFromMap(jobIndustryMap, "name", "");
					sb.append(jobIndustryName);
					if (i != expectedJobIndustrys.length - 1) {
						sb.append(",");
					}
				}
				expectedJobIndustryName = sb.toString();

				// 期望工作职业 多个也逗号隔开
				String expectedJobCareer = CommonUtils.getStrValueFromMap(userMap, "expectedJobCareer", "");
				String[] expectedJobCareers = expectedJobCareer.split(",");
				sb = new StringBuffer();
				for (int i = 0; i < expectedJobCareers.length; i++) {
					String jobCareersId = expectedJobCareers[i];
					Map<String, Object> jobCareersMap = cacheService.getPlace(jobCareersId);

					String jobCareersName = CommonUtils.getStrValueFromMap(jobCareersMap, "name", "");
					sb.append(jobCareersName);
					if (i != expectedJobCareers.length - 1) {
						sb.append(",");
					}
				}
				expectedJobCareerName = sb.toString();

				// 工作地区
				String expectedJobArea = CommonUtils.getStrValueFromMap(userMap, "expectedJobArea", "");
				String[] expectedJobAreas = expectedJobArea.split(",");
				sb = new StringBuffer();
				for (int i = 0; i < expectedJobAreas.length; i++) {
					String jobAreasId = expectedJobAreas[i];
					Map<String, Object> jobAreasMap = cacheService.getPlace(jobAreasId);
					String jobAreasName = CommonUtils.getStrValueFromMap(jobAreasMap, "name", "");
					sb.append(jobAreasName);
					if (i != expectedJobAreas.length - 1) {
						sb.append("-");
					}
				}
				expectedJobAreaName = sb.toString();
				result = new ModelAndView("/h5/jobIntension");
				result.addObject("expectedJobIndustryName", expectedJobIndustryName);
				result.addObject("expectedJobCareerName", expectedJobCareerName);
				result.addObject("expectedJobAreaName", expectedJobAreaName);
				result.addObject("jobPayList", DictUtils.getDictList("job_pay"));
				result.addObject("recruitmentNatureList", DictUtils.getDictList("recruitment_nature"));
			} else {
				List learningList ;
				List workList ;
				if(StringUtils.isNotBlank(userJobSeekerId)){
					param.put("jobId", userJobSeekerId);
					userMap = resumeService.findResumeMapByMap(param);
				}
				//判断有没有填写信息时
				if(userMap!=null){
					String learningExperience = CommonUtils.getStrValueFromMap(userMap, "learningExperience", "");
					String workExperience = CommonUtils.getStrValueFromMap(userMap, "workExperience", "");
					learningList = JSONObject.parseArray(learningExperience, Map.class);
					workList = JSONObject.parseArray(workExperience, Map.class);
				}else {
					learningList = new ArrayList();
					workList = new ArrayList();
				}

				List<Map<String, Object>> newLearningList = new ArrayList<>();
				List<Map<String, Object>> newWorkList = new ArrayList<>();
				for (int i = 0; i < learningList.size(); i++) {
					Map<String, Object> map = (Map<String, Object>) learningList.get(i);
					String startId = String.format("learnStartDate%s", i + 1);
					String endId = String.format("learnEndDate%s", i + 1);
					map.put("startId", startId);
					map.put("endId", endId);
					newLearningList.add(map);
				}
				for (int i = 0; i < workList.size(); i++) {
					Map<String, Object> map = (Map<String, Object>) workList.get(i);
					String startId = String.format("workStartDate%s", i + 1);
					String endId = String.format("workEndDate%s", i + 1);
					map.put("startId", startId);
					map.put("endId", endId);
					newWorkList.add(map);
				}
				int learningCount = learningList.size();
				int workCount = workList.size();
				result = new ModelAndView("/h5/resume");
				result.addObject("learningList", newLearningList);
				result.addObject("learningCount", learningCount);
				result.addObject("workList", newWorkList);
				result.addObject("workCount", workCount);
				result.addObject("resumeId", userMap.get("id"));
			}
		} catch (Exception e) {
			super.dealException(ErrorEnums.SYSTEM_ERROR, e, apiResult, logger);
		}
		result.addObject("userMap", userMap);
		result.addObject("jobId", userJobSeekerId);
		getUserMapByToken(request, result);
		return result;
	}



}
